//
//  ShoppingLayer.h
//  ATM Killer
//
//  Created by Cloner Team on 9/26/14.
//
//

#ifndef SHOPPING_LAYER_H
#define SHOPPING_LAYER_H

#include "AbstractLayer.h"
using namespace extension;
class ShoppingLayer : public AbstractLayer {
    UG_PROPERTY_GETTER(GameModel*, gameModel, GameModel);
    UG_PROPERTY_FULL(Layer*, boardLayer, BoardLayer);
    UG_PROPERTY_FULL(Layer*, cardLayer, CardLayer);
    UG_PROPERTY_FULL(Layer*, avatarLayer, AvatarLayer);
    UG_PROPERTY_FULL(Layer*, popUpLayer, PopUpLayer);
    UG_PROPERTY_FULL(Label*, currentMoneyLabel, CurrentMoneyLabel);
    UG_PROPERTY_FULL(Label*, nameLabel, CharacterNameLabel);
    UG_PROPERTY_FULL(Label*, mpsLabel, MpsLabel);
    UG_PROPERTY_FULL(Label*, upgradeNameLabel, UpgradeNameLabel);
    UG_PROPERTY_FULL(Label*, upgradeEffectLabel, UpgradeEffectLabel);
    UG_PROPERTY_FULL(Label*, requiredMoneyLabel, RequiredMoneyLabel);
    UG_PROPERTY_FULL(Label*, upgradeDescLabel, UpgradeDescLabel);
    UG_PROPERTY_FULL(Label*, upgradeCostLabel, UpgradeCostLabel);
    UG_PROPERTY_FULL(MenuItemSprite*, purchaseButton, PurchaseButton);
    UG_PROPERTY_FULL(MenuItemSprite*, continueButton, ContinueButton);
    UG_PROPERTY_FULL(MenuItemSprite*, okButton, OkButton);
    UG_PROPERTY_FULL(MenuItemSprite*, cancelButton, CancelButton);
    UG_PROPERTY_FULL(__Array*, cardArray, CardArray);
    UG_PROPERTY_FULL(__Array*, pageButtons, PageButtons);
    UG_PROPERTY_FULL(__Dictionary*, avatars, Avatars);
    
private:
    bool isPopUpShow;
    int cardDirection = NUM_CARDS_HALT;
    bool swipe = false;
    int contentOffsetSpeed;
    float finishContentOffset;
    cocos2d::Point pointSwipe;
    float timeOfSwipe = 0.0f;
    
    int currentChoosenPage;
    int currentAvatarID;
    int currentBonusCard;
    int cardChoice;
    Face* shoppingBoard;
    Face* popUpFace;
    UGLayerColor* grayLayer;
    ScrollView* cardContentView;
    ShoppingListener* shoppingListener;
    NotificationListener* notificationListener;
    virtual void onEnter();
    virtual void onExit();
    void onButtonClick(Ref* sender);
    
    void touchesRegister();
    
    void initialize();
    void createLayers();
    void createLayersContent();
    void loadShoppingBoard();
    void loadPopUp();
    void loadAvatar();
    void onChangeAvatar(Ref* data);
    void onShowBonusNoti(Ref* data);
    void onRemoveBonusNoti(Ref* data);
    void cancelPopUp(Ref* sender);
    void showBonusPopUp(Ref* sender);
    void createCards();
    void arrangeCards();
    void createPageButtons();
public:
    void onTouchesBegan(const std::vector<Touch*>& touches, Event* event);
    void onTouchesMoved(const std::vector<Touch*>& touches, Event* event);
    void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
    ShoppingLayer();
    ~ShoppingLayer();
    virtual void update(float dt);
    CREATE_FUNC(ShoppingLayer);
    
};

#endif
